/* -*- Mode: C; tab-width: 4;  c-basic-offset: 4          -*- */
/*
 * viewer.h
 *
 * Copyright (C) 2008, 2009 Lingtao Pan
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, 
 * Boston, MA 02111-1307, USA.
 */


#ifndef GFTP_VIEWER_H
#define GFTP_VIEWER_H

enum {
  COLUMN_STOCK = 0,
  COLUMN_FILENAME, 
  COLUMN_FILESIZE,
  COLUMN_USER,
  COLUMN_GROUP,
  COLUMN_DATE,
  COLUMN_ATTRIBS,
  COLUMN_FILEENTRY,
  COLUMNS
};


/* TODO: If other modules don't need to see this structure,
 * put it to viewer.c
 **/
typedef struct HistoryEntry {
    gchar    *path;
    int       pos;
} HistoryEntry;



typedef struct Viewer
{
    GtkWidget *combo,   /* Entry widget/history for the user to enter 
                           a directory */
        *treeview,              /* Our listbox showing the files */
        *filter_entry;

    gulong ccc_id;              /* combo changed callback handler io */

    GtkWidget *upbtn,           /* go up */
        *backbtn,
        *fwdbtn,
        *rfrbtn,                /* refresh */
        *stopbtn;

    GtkListStore *store;
    GtkTreeModel *filter;
    GtkTreeViewColumn *first_column;
    GtkWidget *frame;
    GtkWidget *vbox;
    
    gchar *filter_str;
    GPatternSpec*  pattern_spec;
    
    unsigned int sorted : 1,   /* Is the output sorted? */
        show_selected : 1,     /* Show only selected files */
        *histlen;              /* Pointer to length of history */
    char *filespec;            /* Filespec for the listbox */
    gftp_request *request;     /* The host that we are connected to */
    GList * files;             /* Files in the listbox */

    GList  *history;  /* Navigation history */
    GList  *his_pos;  /* Position in history, NULL means we are not in
                       * history navigation, otherwise it should point
                       * to the position of current directory in the history.
                       */
    int    his_len;
    
    pthread_t tid;              /* Thread for the stop button */
} Viewer;

#define MAX_HIS_LEN 20



Viewer* gftp_viewer_new ();
void  gftp_viewer_clear ();
void  gftp_viewer_refresh (Viewer *viewer);
void* gftp_viewer_get_file_list (Viewer *viewer);

void gftp_viewer_show_files (Viewer *viewer);

void gftp_viewer_add_directory_history (Viewer *viewer, gchar *dir, int pos);

void gftp_viewer_combo_set_text (Viewer *viewer, gchar *text);
void gftp_viewer_combo_set_text_no_emission (Viewer *viewer, gchar *text);
int  gftp_viewer_get_tree_view_position (Viewer *viewer);
void gftp_viewer_copy_filename (Viewer *viewer);

void gftp_viewer_navigation_disable (Viewer *viewer);
void gftp_viewer_navigation_enable  (Viewer *viewer);
void on_viewer_init (Viewer *viewer);
void on_viewer_connecting (Viewer *viewer);
void on_viewer_connected (Viewer *viewer);
void on_viewer_directory_history_set (Viewer *viewer);
void on_viewer_backbtn_clicked (Viewer *viewer);

#endif
